﻿// exercise4.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <stdio.h>
#include<math.h>

int power(int a, int n)
{
	int product = a;
	for (int i = 0; i < n; i++) {
		product *= a;
	}

	return product;
}
int quick_pow(int a, int n)
{
	int product = 1;
	while (n) {
		if (n & 1) {
			product = (product * a);
		}
		a = a * a;
		n >>= 1;
	}

	return product;
}
//7-1 数位和
void ex4_7_1()
{
	int n = 0;
	scanf("%d", &n);
	if (n < 10)
		printf("%d", n);
	else
		printf("%d", n % 9 == 0 ? 9 : n % 9);
}

//7-2 考拉兹猜想
void ex4_7_2()
{
	long long n, cnt = 0;
	scanf("%lld", &n);
	while (n > 1) {
		if (n % 2 == 0)
			n = n / 2;
		else
			n = n * 3 + 1;
		cnt++;
	}
	printf("%d", cnt);
}
//7-3 完全平方数
void ex4_7_3()
{
	int n = 0;
	scanf("%d", &n);
	int sr = sqrt(n);
	if (sr * sr == n)
		printf("%d", sr);
	else
		printf("0");
}
//7-4 正整数解
void ex4_7_4()
{
	int x, y;
	int n;
	scanf("%d", &n);
	x = 1;
	y = sqrt(n - 1);
	int not_found = 1;
	while (x <= y) {
		if (x * x + y * y == n) {
			printf("%d %d\n", x++, y--);
			not_found = 0;
		}
		else if (x * x + y * y > n) {
			y--;
		}
		else {
			x++;
		}
	}
	if (not_found)
		printf("No solution");
}

//7-5 水仙花数
void ex4_7_5()
{
	int len = 0;
	scanf("%d", &len);

	int lower = power(10, len - 1);
	int upper = power(10, len);
	int temp, sum;
	for (int i = lower; i < upper; i++) {
		temp = i;
		sum = 0;
		while (sum <= i && temp) {
			sum += power(temp % 10, len);
			temp = temp / 10;
		}
		if (sum == i)
			printf("%d\n", i);
	}
}

int main()
{
	return 0;
}